/***********************************************************************//**
 *   \file Buffer.h		\author belot nicolas (karrakis)            
 *   \brief define Class Buffer                                                  
 *   a basic buffer storing array of double                                
 ************************************************************************//*
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/

#ifndef BUFFER_H
#define BUFFER_H 1

#include "libtrckr.h"
#include <sys/types.h>
#include <stdlib.h>
#include <stdexcept>
namespace libtrckr {
/** amespace libtrckr
   \brief the namespace of the librairie.
*/

class Buffer{
	/** \class libtrckr::Buffer
	\brief An Buffer for Handling data
	*/
	public:
		//Constructor
		/** Create an Empty Buffer with a size of 1024 */
		Buffer();
		/** Create an Empty Buffer of the specified side
		\param size the size
		*/
		Buffer(int);
		/** Create an new Buffer containing data 
		\param data the data...
		\param size the size of the data \b and the buffer
		*/
		Buffer(double*, int);
		/** Create a new Buffer of the specified size and loads data in 
		\param data the data
		\param position the size of the data
		\param size the size of the buffer*/
		Buffer(double*,int,int);
		/** copy Constructor */
		Buffer(const Buffer&);

		/**Destructor*/
		~Buffer();

		//Accessor
		/** return the size of the data */
		size_t size() const;
		/** return the size of the buffer */
		size_t capacity() const;
		/** return the pointer of data */
		double *getContent() const;
		/** Is the buffer full */
		bool full() const;
		/** return the size of the data*/
		size_t position() const;
		/** return the size of the buffer*/
		size_t end() const;
		//truc
		/** append the data in the buffer */
		void append(const Buffer& );
		/** append the data in the buffer 
		\param data data to append
		\param size size of the data
		*/
		void append(double*, size_t);
		/** append the data in the buffer 
		\param data data to append
		\param size size of the data
		\param channels number of channels
		*/
		void append(double*, size_t, int);

		void channels(int);
		int channels() const;

		void setChannel(int);
		int getChannel() const;

		bool hasNextChannel();
		void nextChannel();

		void clearChannel();
		/** Empty the buffer */
		void flush();
		//operator
		/** Access to element i*/
		double operator [] (unsigned int) const;
		/** Access to element i*/
		double& operator [] (unsigned int);
		
		/** concatenate 2 buffer in one */
		Buffer operator+(const Buffer&) const;
		/** Append data in the Buffer */
		void operator+=(const Buffer&);
		/** Append data in the Buffer */
		void operator<<(const Buffer&);
		/** Copy */
		Buffer operator=(const Buffer&);
	private:
		static const size_t SIZE=1024;
		size_t _size;
		size_t _position;
		double* _buffer;
		unsigned short int _channels;
		unsigned short int _current;

};

}

#endif

